package me.ereach.streams;

import java.util.List;
import java.util.stream.Collectors;

public class Main13Grouping {
    public static void main(String[] args) {
        List<Movie> movies = List.of(
                new Movie("a", 10, Genre.THRILLER),
                new Movie("b", 15, Genre.ACTION),
                new Movie("c", 20, Genre.ACTION)
        );

        System.out.println("===toSet");
        var rst = movies.stream()
                .collect(Collectors.groupingBy(Movie::getGenre, Collectors.toSet()));

        System.out.println(rst);

        System.out.println("===counting");
        var rst1 = movies.stream()
                .collect(Collectors.groupingBy(Movie::getGenre, Collectors.counting()));

        System.out.println(rst1);

        System.out.println("===counting");
        var rst2 = movies.stream()
                .collect(Collectors.groupingBy(
                        Movie::getGenre,
                        Collectors.mapping(
                                Movie::getTitle,
                                Collectors.joining(", "))));

        System.out.println(rst2);
    }
}
